/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:57 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class Khoahoc_HocvienDAL : SqlProvider<Khoahoc_HocvienEntity>
    {
        static Khoahoc_HocvienDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                Khoahoc_HocvienEntity entity = new Khoahoc_HocvienEntity();
                entity.PK_iKhoahoc_HocvienID = Int64.Parse("0" + dr["PK_iKhoahoc_HocvienID"].ToString());
				entity.FK_iKhoahocID = Int64.Parse("0"+dr["FK_iKhoahocID"].ToString());
				entity.FK_iHocvienID = Int64.Parse("0"+dr["FK_iHocvienID"].ToString());
				entity.iTrangthai = Int16.Parse("0"+dr["iTrangthai"].ToString());
				entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static Khoahoc_HocvienEntity GetOne(Int64 PK_iKhoahoc_HocvienID)
        {
            string cmdName = "spKhoahoc_Hocvien_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iKhoahoc_HocvienID", PK_iKhoahoc_HocvienID);
            Khoahoc_HocvienEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static Khoahoc_HocvienEntity GetByFK_iKhoahocIDAndFK_iHocvienID(Int64 FK_iKhoahocID, Int32 FK_iHocvienID)
        {
            string cmdName = "spKhoahoc_Hocvien_GetByFK_iKhoahocIDAndFK_iHocvienID";
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            p[1] = new SqlParameter("@FK_iHocvienID", FK_iHocvienID);
            Khoahoc_HocvienEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<Khoahoc_HocvienEntity> GetAll()
        {
            string cmdName = "spKhoahoc_Hocvien_Get";
            return GetList(cmdName);
        }
        public static List<Khoahoc_HocvienEntity> GetByFK_iKhoahocID(Int64 FK_iKhoahocID)
        {
            string cmdName = "spKhoahoc_Hocvien_GetByFK_iKhoahocID";
            SqlParameter p = new SqlParameter("@FK_iKhoahocID", FK_iKhoahocID);
            List<Khoahoc_HocvienEntity> list = GetList(cmdName, p);
            return list;
        }
        public static List<Khoahoc_HocvienEntity> GetByFK_iHocvienID(Int64 FK_iHocvienID)
        {
            string cmdName = "spKhoahoc_Hocvien_GetByFK_iHocvienID";
            SqlParameter p = new SqlParameter("@FK_iHocvienID", FK_iHocvienID);
            List<Khoahoc_HocvienEntity> list = GetList(cmdName, p);
            return list;
        }
        public static int Add(Khoahoc_HocvienEntity entity)
        {
            string cmdName = "spKhoahoc_Hocvien_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(Khoahoc_HocvienEntity entity)
        {
            string cmdName = "spKhoahoc_Hocvien_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iKhoahoc_HocvienID)
        {
            string cmdName = "spKhoahoc_Hocvien_Delete";
            SqlParameter p = new SqlParameter("@PK_iKhoahoc_HocvienID", PK_iKhoahoc_HocvienID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(Khoahoc_HocvienEntity entity)
        {
            SqlParameter[] p = new SqlParameter[5];
            p[0] = new SqlParameter("@PK_iKhoahoc_HocvienID", entity.PK_iKhoahoc_HocvienID);
			p[1] = new SqlParameter("@FK_iKhoahocID", entity.FK_iKhoahocID);
			p[2] = new SqlParameter("@FK_iHocvienID", entity.FK_iHocvienID);
			p[3] = new SqlParameter("@iTrangthai", entity.iTrangthai);
			p[4] = new SqlParameter("@sGhichu", entity.sGhichu);
            return p;
        }
        #endregion
       
    }
}